package com.zhijiang.hospital.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhijiang.hospital.entity.dto.SocietyServiceDataDto;
import com.zhijiang.hospital.mapper.SocietyServiceDataMapper;
import com.zhijiang.hospital.service.SocietyServiceDataService;
import com.zhijiang.util.BaseQuery;
import com.zhijiang.util.NumberUtils;
import com.zhijiang.util.PageList;
import com.zhijiang.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_data
 * @description
 * @date 2023-02-21 14:43:11
 */
@Service
public class SocietyServiceDataServiceImpl implements SocietyServiceDataService {
    @Autowired
    SocietyServiceDataMapper societyServiceDataMapper;

    @Override
    public PageList<SocietyServiceDataDto> findSocietyServiceData(BaseQuery baseQuery) {
        PageHelper.startPage(baseQuery.getPage(), baseQuery.getPageSize());
        List<SocietyServiceDataDto> societyServiceData = societyServiceDataMapper.findSocietyServiceData(baseQuery.getStartTime(), baseQuery.getEndTime());
        PageInfo<SocietyServiceDataDto> pageInfo = new PageInfo<>(societyServiceData);
        Integer pageSize = NumberUtils.drawSurplus(pageInfo.getTotal(), baseQuery.getPageSize());
        Integer pages = NumberUtils.totalPages(pageInfo.getTotal(), baseQuery.getPageSize());
        return new PageList(pageInfo.getTotal(), pageInfo.getList(), baseQuery.getPage(), pageSize, pages);
    }

    @Override
    public List<SocietyServiceDataDto> loadSocietyServiceDataYear() {
        DateTime dateTime = DateUtil.beginOfYear(new Date());
        String year = String.valueOf(DateUtil.year(dateTime));
        DateTime dateTime1 = DateUtil.endOfYear(new Date());
        String startTime = Convert.toStr(dateTime);
        String endTime = Convert.toStr(dateTime1);
        List<SocietyServiceDataDto> list = societyServiceDataMapper.findSocietyServiceData(startTime, endTime);
        return list;
    }

    @Override
    public List<SocietyServiceDataDto> loadSocietyServiceDataLastYear() {
        Date nextYearPreDay = TimeUtil.getNextYearPreDay();
        DateTime dateTime3 = DateUtil.beginOfYear(nextYearPreDay);
        String lastYear = String.valueOf(DateUtil.year(dateTime3));
        DateTime dateTime4 = DateUtil.endOfYear(nextYearPreDay);
        String format = TimeUtil.format(dateTime3);
        String format1 = TimeUtil.format(dateTime4);
        List<SocietyServiceDataDto> societyServiceData = societyServiceDataMapper.findSocietyServiceData(format, format1);
        return societyServiceData;
    }

}
